package com.jiuxian.example.example2;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

import java.nio.charset.Charset;

public class ByteBufTest2 {
    public static void main(String[] args) {
        ByteBuf buffer = Unpooled.copiedBuffer("hello world", Charset.forName("utf-8"));

        if (buffer.hasArray()) {
            byte[] content = buffer.array();
            System.out.println(new String(content, Charset.forName("utf-8")));

            System.out.println("byteBuf: " + buffer);
            System.out.println(buffer.arrayOffset());
            System.out.println(buffer.readerIndex());
            System.out.println(buffer.writerIndex());
            System.out.println(buffer.capacity());
            System.out.println(buffer.readableBytes());
        }
    }
}
